/**
 * Created by Administrator on 2016/6/13.
 */
;(function ($,window,document,undefined) {
  var FontBar = function (ele, opt) {
    this.$element = ele;
    this.defaults = {
      'triggerBtn': this.$element,
      'targetBar': '.font-bar'
    };
    this.options = $.extend({},this.defaults,opt);
  };

  FontBar.prototype = {
    init: function () {
      var _this = this;
      $(this.options.triggerBtn).on('click', function (e) {
        if ($(_this.options.targetBar).css('display') == 'none') {
          $(_this.options.targetBar).show();
        } else {
          $(_this.options.targetBar).hide();
        }
        e.stopPropagation();
      });
      $(_this.options.targetBar).on('click', function (e) {
        e.stopPropagation();
      });
      $('#colorpanel').on('click', function (e) {
        e.stopPropagation();
      });
      $('.font-bar-close-btn').on('click', function (e) {
        $(_this.options.targetBar).hide();
        e.stopPropagation();
      });
      $('#expression-btn').on('click', function () {
        $(_this.options.targetBar).hide();
      });
      $(document).on('click', function () {
        $(_this.options.targetBar).hide();
      });
      $('.font-family-select').on('change', function () {
        $('.ipt-content').css({'font-family': $(this).val()});
      });
      $('.font-size-select').on('change', function () {
        $('.ipt-content').css({'font-size': $(this).val() + 'px'});
      });
    }
  };

  $.fn.createFontBar = function (option) {
    var fontBar = new FontBar(this, option);
    return fontBar.init();
  };
})(jQuery,window,document);
